﻿using System;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using NLog.Web;
using RAP.Web.Core;

namespace RAP.Web.Core
{
  public class Program
  {
    public static void Main(string[] args)
    {
      var logFac = NLogBuilder.ConfigureNLog("nlog.config");
      var logger = logFac.GetCurrentClassLogger();
      try
      {
        BuildWebHost(args).Run();
      }
      catch (Exception ex)
      {
        logger.Error(ex);
      }
    }

    public static IWebHost BuildWebHost(string[] args)
    {
      var config = new ConfigurationBuilder()
        .AddJsonFile("hosting.json", optional: true)
        .AddCommandLine(args)
        .Build();
      return WebHost.CreateDefaultBuilder(args)
        .UseConfiguration(config)
        .ConfigureKestrel(optins => {
          optins.AllowSynchronousIO = true; // 允许异步读取Http的请求数据
        })
        .UseStartup<Startup>()
        .Build();
    }

  }
}
